package com.dongdong.index;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdong.pojo.TbSeller;
import com.dongdong.service.LoginService;
import com.dongdongshop.configresult.Result;
import com.dongdongshop.em.ResultEnum;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

@Controller
@RequestMapping("login")
public class LoginController {

    //    登录
    @RequestMapping("entry")
    public String entry(String uname, String upwd, Model m){
//      借助shiro登录
//         创建subject
        Subject subject = SecurityUtils.getSubject();
//        封装token
        UsernamePasswordToken token = new UsernamePasswordToken(uname,upwd);
        try {
            subject.login(token);
        }catch (UnknownAccountException a){
            m.addAttribute("msg","账号错误");
            return "/login";
        }catch (IncorrectCredentialsException b){
            m.addAttribute("msg","密码错误");
            return "/login";
        }
        return "/admin/index";
    }

}
